export default {

    install(Vue) {
        //这里是示例方法 getTime是方法名 function()可以携带参数
        Vue.prototype.getTime = function () {
            var date = new Date()
            var y = date.getFullYear()
            var m = date.getMonth() + 1
            m = m < 10 ? ('0' + m) : m
            var d = date.getDate()
            d = d < 10 ? ('0' + d) : d
            alert(y + m + d)
        };


        Vue.prototype.stateFormat = function (row, column, cellValue) {
            if (cellValue) {
                return Number(cellValue)
                    .toFixed(2)
                    .replace(/(\d)(?=(\d{3})+\.)/g, ($0, $1) => {
                        return $1 + ",";
                    })
                    .replace(/\.$/, "")
            }
        };

        Vue.prototype.getSummaries = function (param) {
            const { columns, data } = param;
            const sums = [];
            columns.forEach((column, index) => {
                if (index === 0) {
                    sums[index] = '总价';
                    return;
                }
                const values = data.map(item => Number(item[column.property]));
                if (!values.every(value => isNaN(value))) {
                    sums[index] = values.reduce((prev, curr) => {
                        const value = Number(curr);
                        if (!isNaN(value)) {
                            return prev + curr;
                        } else {
                            return prev;
                        }
                    }, 0);
                    sums[index] = sums[index].toFixed(2);
                    // sums[index] += ' ';
                } else {
                    sums[index] = '';
                }

            });

            return sums;
        };



    },


}

